﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.Domain.Entities;
using SeaBattle.Domain.Abstract;

namespace SeaBattle.Domain.Concrete.Services
{
    public class FakePlayerService: IPlayerService
    {

        private IPlayerRepository playerRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="FakePlayerService"/> class.
        /// </summary>
        /// <param name="playerRepository">The player repository.</param>
        /// <remarks></remarks>
        public FakePlayerService(IPlayerRepository playerRepository)
        {
            this.playerRepository = playerRepository;
        }

        /// <summary>
        /// Players the exists.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public bool PlayerExists(string name)
        {

            return playerRepository.Players.ToList().Exists(x => x.Name == name);
        }

        /// <summary>
        /// Registers the new player.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <remarks></remarks>
        public void RegisterNewPlayer(Player player)
        {
            playerRepository.SavePlayer(player);
        }

        /// <summary>
        /// Gets the player.
        /// </summary>
        /// <param name="login">The login.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public Player GetPlayer(string login)
        {
            return playerRepository.GetPlayer(login);
        }
    }
}
